$(function() {
	/*
	$('#mega-menu-1').dcMegaMenu({
		'speed' : 'fast',
		'fullWidth' : true,
		rowItems : 5
	});
	*/
	

	
	/* HIDE CONTROLLER BAR IF EMPTY*/
	if($.trim($('div.navigation.controller div').html()) == "") {
		$('div.navigation.controller').hide();
		$('div.main-content').css({"margin-left": "0px"});
	} else {
		$('div.navigation.controller').show();
		$('div.main-content').css({"margin-left": "225px"});
	} 
	
	// HIDE ALL ACTION NAVIGATION
	$('div.navigation.controller div a.action-navigation').hide();
	
	// MOVE ACTIVE CONTROLLER ACTION TO DIV
	var cList = $('div.navigation.action ul');
	$(cList).empty();
			
	$('div.navigation.controller div a.action-navigation').each(function(index, elem) {
		if ($(elem).parent('li').parent('ul').parent('li').hasClass('active')) {
			//alert($(elem).html());
			$('<li/>').append(elem).appendTo(cList);
		}
	});
	$('div.navigation.action a').show();
	
	/* HIDE ACTION BAR IF EMPTY*/
	if($.trim($('div.navigation.action ul').html()) == "") {
		$('div.navigation.action').hide();
		//$('div.main-content').css({"margin-top": "50px"});
	} else {
		$('div.navigation.action').show();
		//$('div.main-content').css({"margin-top": "100px"});
	} 
	
	
	/* HIDE BREADCRUMB IF EMPTY */	
	if($.trim($('div.main-content div.breadcrumbs').html()) == "") {
		$('div.main-content div.breadcrumbs').hide();
	} else {
		$('div.main-content div.breadcrumbs').show();
	}
	
	
	
	/* NAVIGATION ONLY SHOW ACTIVE MODULE */
	/*
	$('div.navigation.controller ul.navigation > li').each(function(index, elem) {
		if ($(elem).hasClass("active")) {
			$(elem).children("ul:first").show();
		} else {
			$(elem).children("ul:first").hide();
		}
	});
	*/
	
	/* GRIDVIEW FIX SCROLL */
	$('div.gridview')
			.each(
					function(index, elem) {
						var column_wrapper = $(elem).find(
								'div.gridview-body-column-wrapper')[0];
						var row_wrapper = $(elem).find(
								'div.gridview-body-row-wrapper')[0];
						var total_wrapper = $(elem).find(
								'div.gridview-body-total-wrapper')[0];

						$(row_wrapper).scroll(
								function() {
									$(column_wrapper).scrollLeft(
											$(row_wrapper).scrollLeft());
									$(total_wrapper).scrollLeft(
											$(row_wrapper).scrollLeft());
								});
					});

	/* GRIDVIEW ANIMATION */
	if ($('div.gridview input').length) {
		$('div.gridview input')
				.focus(
						function() {
							$('div.gridview div.gridview-body-row-wrapper table tr').css('background-color', 'white');
							$('div.gridview div.gridview-body-row-wrapper table tr input').css('background-color', 'white');

							$(this).parents('tr').css('background-color',
									'#FFF2B1');
							$(this).parents('tr').find('input').css(
									'background-color', '#FFF2B1');
							$(this).css('background-color', 'white');
						});
	} else {
		$('div.gridview div.gridview-body-row-wrapper td').click(
				function() {
					$('div.gridview div.gridview-body-row-wrapper table tr').css('background-color', 'white');
					$('div.gridview div.gridview-body-row-wrapper table tr td').css('background-color', 'white');
					
					$(this).parents('tr').find('td').css('background-color', '#FFF2B1');
					$(this).css('background-color', '#FFE771');
				});
	}

});

function ajaxUpdater(method, action, params, container) {
	ajaxUrl = web_base_path + action.split('.').join('/');

	$.ajax({
		url : ajaxUrl,
		type : method,
		dataType : "html",
		data : params,
		success : function(resp) {
			$(container).html(resp);
		},
		error : function(e) {
			alert(e);
		}
	});
}

function ajaxRequest(method, action, params, callback) {
	ajaxUrl = web_base_path + action.split('.').join('/');
	
	$.ajax({
		url : ajaxUrl,
		type : method,
		dataType : "html",
		data : params,
		success : function(resp) {
			resp = jQuery.parseJSON(resp);
			if (resp.redirect) {
				window.location.href = resp.redirect_url;
			}
		},
		error : function(e) {
			alert(e);
		}
	});
}

function redirect() {
	
}